package com.sbj.controller;

import cn.dev33.satoken.stp.StpUtil;
import cn.hutool.core.convert.Convert;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.sbj.dto.req.MemberPassReq;
import com.sbj.dto.req.MemberReq;
import com.sbj.dto.req.MemberStoreReq;
import com.sbj.dto.req.OrderReq;
import com.sbj.dto.res.*;

import com.sbj.entity.Order;
import com.sbj.service.*;
import com.zmh.framework.util.Result;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.validation.Valid;
import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

/**
 * @author summer
 * @version 1.0
 * @date 2024/8/11 20:25
 */
@RestController
@RequestMapping(value = "/set")
@AllArgsConstructor
public class MemberSetController {


    private final IMemberService memberService;

    /**
     * 上传头像
     * @param file
     * @return
     */
    @PostMapping(value = "/uploadAvatar")
    public Result<String> uploadAvatar(MultipartFile file) {
        return Result.successResult(memberService.uploadAvatar(file));
    }

    /**
     * 修改昵称
     * @param memberReq
     * @return
     */
    @PostMapping(value = "/modifyNickName")
    public Result<String> modifyNickName(@RequestBody MemberReq memberReq) {
        memberService.editNickName(memberReq);
        return Result.successResult();
    }



    private final IMemberStoreService memberStoreService;

    /**
     * 仓库订单
     * 买家订单
     * @param req
     * @return
     */
    @PostMapping(value = "/buyer_order")
    public Result<Page<MemberStoreRes>> buyerOrderLists(@RequestBody MemberStoreReq req){
        return Result.successResult(memberStoreService.buyerOrderLists(req));
    }


    /**
     * 修改密码
     * @param req
     * @return
     */
    @PostMapping(value = "/modifyPassword")
    public Result<String>  modifyPassword(@Valid  @RequestBody MemberPassReq req){
        memberService.editPassword(req);
        return Result.successResult();
    }

    /**
     * 邀请人数
     * @return
     */
    @GetMapping(value = "/invitationList")
    public Result<List<InvitationRes>> invitationList(){
        return Result.successResult(memberService.invitationList());
    }

    /**
     * 粉丝
     * @return
     */
    @GetMapping(value = "/fansList")
    public Result<List<FansRes>>  fansLists(){
        return Result.successResult(memberService.fansLists());
    }

    private final OrderService orderService;

    /**
     * 商城订单
     * @param req
     * @return
     */
    @PostMapping(value = "/orderList")
    public Result<Page<ShopOrderRes>>  orderList(@RequestBody OrderReq req){
        return Result.successResult(orderService.lists(req));
    }



    /**
     * 邀请码
     * @return
     */
    @GetMapping(value = "/findMemberInviterCode")
    public Result<InviterCodeRes> findMemberInviterCode(){
        return Result.successResult(memberService.findMemberInviterCode());
    }

    /**
     * 获取当前用户信息
     * @return
     */
    @GetMapping(value = "/findMemberInfo")
    public Result<MemberRes> findMemberInfo(){
        return Result.successResult(memberService.findMemberInfo());
    }

    /**
     * 系统退出
     * @return
     */
    @GetMapping(value = "/logout")
    public Result<String> logout(){
        StpUtil.logout(StpUtil.getLoginIdAsInt());
        return Result.successResult();
    }

    private final IIncomeService incomeService;

    /**
     * 当天推广收益
     * @return
     */
    @GetMapping(value = "/cur_date_extension")
    public Result<ExtensionAmountRes> curDateExtension(){

        return Result.successResult(incomeService.curDateExtension());
    }


}
